package com.jzwl.xydk.sendmessage;

import java.util.Date;
import java.util.Map;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.jzwl.common.constant.Constants;
import com.jzwl.common.utils.DateUtil;
import com.jzwl.common.utils.HttpClientUtil;

@Service("sendMessage")
public class SendMessage {
	
	@Autowired
	private Constants constants;
	
	
	
	public void sendAuditSuccessMessage(Map<String,Object> map){
		
		try {
			StringBuffer detail = new StringBuffer();
			WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
			templateMessage.setToUser(map.get("openId").toString());
			//templateMessage.setToUser("o3P2SwZCegQ-M6AG4-Nukz5R8gN8");
			templateMessage.setTemplateId("SiZUQrk4qT0A87hfku2nQHZcMDlTUFCq5DyQShh-4To");
			templateMessage.setUrl(constants.getTemplateMessage_to_my_url());
			templateMessage.getDatas().add(new WxMpTemplateData("first", map.get("auditType").toString()));
			templateMessage.getDatas().add(new WxMpTemplateData("keyword1", map.get("userName").toString()));
			templateMessage.getDatas().add(new WxMpTemplateData("keyword2", map.get("phoneNumber").toString()));
			templateMessage.getDatas().add(new WxMpTemplateData("keyword3", DateUtil.formatDate(new Date())));
		
			detail.append("如有任何问题请拨打校咖微平台官方客服电话：4008-108-789");
			templateMessage.getDatas().add(new WxMpTemplateData("remark", detail.toString()));
			//		wxMpService.templateSend(templateMessage);
			Gson gson = new Gson();
			String json = gson.toJson(templateMessage);
			String urlString=constants.getXiaoka_weixin_wm_sendTemplateByOpenId();
			HttpClientUtil.requestByPostMethod(urlString,json,"templateMessage","audit");
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	
	

}
